<template>
  <div class="app">
    <NavMenu v-if="user.length>0"></NavMenu>
    <router-view v-if="isRouterAlive"></router-view>
  </div>
</template>
<script>
import NavMenu from "@/components/view/NavMenu";
import { mapState, mapGetters, mapMutations, mapActions } from "vuex";
export default {
  name: "App",
  provide() {
    return {
      reload: this.reload
    };
  },
  data() {
    return {
      isRouterAlive: true
    };
  },
  methods: {
        ...mapMutations(["xguser"]),
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(function() {
        this.isRouterAlive = true;
      });
    }
  },
  components: {
    NavMenu
  },
  computed: {
    ...mapState(["leixing"]),
    ...mapState(["poot"]),
    ...mapState(["user"]),
    ...mapState(["gerenindex"])
  },
  mounted() {
    if (localStorage.getItem("mailbox") != null) {
      this.$http
        .post(this.poot + "login", {
          mailbox: localStorage.getItem("mailbox"),
          password:localStorage.getItem("password")
        })
        .then(response => {
          if (response.data == "ok") {
            this.xguser(localStorage.getItem("mailbox"));
            this.$router.push("/home");
          } else {
            this.$router.push("/denglu");
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    }else{
       this.$router.push("/denglu");
    }

  
  }
};
</script>
<style>
/* .app{
  overflow: auto;
}
.app::-webkit-scrollbar {
  display: none;
} */

body {
  margin: 0px;
  width: 100%;
  min-width: 1500px;
  max-width: 100%;
  height: 100%;
  background-color: #f0f0f0;
}
#head {
  background-color: #ffff00;
  width: 100%;
  height: 100px;
}
#center {
  background-color: #00ffff;
  width: 100%;
  min-height: 100%;
}
#foot {
  background-color: #ff00ff;
  width: 100%;
  height: 100px;
}
</style>
